﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Collections;
using System.Data.OleDb;
using System.IO;

namespace LCWMS
{
    public partial class w_itf001 : DockContent
    {
        //返回的商品信息 格式sku
        public static string str_skucode;
        DataTable add_detail = new DataTable();
        private string str_updatesql;
        private DataSet ds_update;
        private DataSet dscustomer;
        private string str_time;
        decimal d_sum = 0;
        decimal d_count = 0;
        public w_itf001()
        {
            InitializeComponent();
            dgv_asn.AutoGenerateColumns = false;
            dgv_export.AutoGenerateColumns = false;
            //  dgv_execl.AutoGenerateColumns = false;
        }
        public static ArrayList GetExcelTables(string FilePath)
        {
            //将Excel架构存入数据里
            DataTable dt = new DataTable();
            ArrayList TablesList = new ArrayList();

            if (File.Exists(FilePath))
            {
                using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet." +
                     "OLEDB.4.0;Extended Properties=\"Excel 8.0\";Data Source=" + FilePath))
                {
                    try
                    {
                        conn.Open();
                        dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    //获取数据表个数
                    int tablecount = dt.Rows.Count;
                    for (int i = 0; i < tablecount; i = i + 2)
                    {
                        string tablename = dt.Rows[i][2].ToString().Trim().TrimEnd('$');
                        if (TablesList.IndexOf(tablename) < 0)
                        {
                            TablesList.Add(tablename);
                        }

                    }
                }
            }
            return TablesList;
        }
        //创建SQL与数据集
        private void f_getsql(string stemp1, string stemp2)
        {
            str_updatesql = "select inv_org,consignor,asn_no,asn_line_no,sku,pack_code,order_qty_m,present_qty_m,order_price,order_unit,main_dist,made_time,maker " +
                           " from " + main.g_space + ".asn_order_detail where inv_org = '" + main.g_org + "' and consignor ='" + stemp1 + "' and asn_no ='" + stemp2 + "' ";
            if (main.dbtype == "SQL")
            {
                ds_update = main.dbservice.Sql_exec_selectsql(str_updatesql);
            }
            else
            {
                ds_update = main.dbservice.oracle_exec_selectsql(str_updatesql);
            }
        }

        //创建SQL与数据集
        private void f_getsql_JS(string stemp1, string stemp2)
        {
            str_updatesql = "select inv_org,consignor,asn_no,asn_line_no,sku,pack_code,order_qty_m,order_qty_s,present_qty_m,present_qty_s,order_price,order_unit,main_dist,made_time,maker,convert_modulus,shelflife_day " +
                           "   ,receive_qty_m,receive_qty_s,receive_present_qty_m,receive_present_qty_s,main_sub_flag,receive_status,tax_dist,lot_attribute3,lot_attribute5,cubage,gross_weight,net_weight from " + main.g_space + ".asn_order_detail where inv_org = '" + main.g_org + "' and consignor ='" + stemp1 + "' and asn_no ='" + stemp2 + "' ";
            if (main.dbtype == "SQL")
            {
                ds_update = main.dbservice.Sql_exec_selectsql(str_updatesql);
            }
            else
            {
                ds_update = main.dbservice.oracle_exec_selectsql(str_updatesql);
            }
        }
        private void f_getsql_WXJS_CP(string stemp1, string stemp2)
        {
            str_updatesql = "select inv_org,consignor,asn_no,asn_line_no,sku,pack_code,order_qty_m,order_qty_s,present_qty_m,present_qty_s,order_price,order_unit,main_dist,made_time,maker,convert_modulus,shelflife_day " +
                           "   ,receive_qty_m,receive_qty_s,receive_present_qty_m,receive_present_qty_s,main_sub_flag,receive_status,tax_dist,cubage,gross_weight,net_weight,lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4,lot_attribute5,lot_attribute6,lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13,lot_attribute14,lot_attribute15,standby_1,standby_3 from " + main.g_space + ".asn_order_detail where inv_org = '" + main.g_org + "' and consignor ='" + stemp1 + "' and asn_no ='" + stemp2 + "' ";
            if (main.dbtype == "SQL")
            {
                ds_update = main.dbservice.Sql_exec_selectsql(str_updatesql);
            }
            else
            {
                ds_update = main.dbservice.oracle_exec_selectsql(str_updatesql);
            }
        }

        private void w_itf001_Load(object sender, EventArgs e)
        {
            //获取按钮权限
            string str_right;
            str_right = main.g_class.comm_getright("w_itf001", main.g_right_dataset);
            //导出
            if (str_right.Substring(0, 1) == "0")
            {
                btn_outexcel.Visible = false;
            }
            else
            {
                btn_outexcel.Visible = true;
            }
            main.g_class.comm_changeControl(this, main.g_win_dataset);

            //明细
            add_detail.Columns.Add("consignor");
            add_detail.Columns.Add("asn_no");
            add_detail.Columns.Add("asn_line_no");
            add_detail.Columns.Add("sku");
            add_detail.Columns.Add("pack_code");
            add_detail.Columns.Add("order_qty_m");
            add_detail.Columns.Add("present_qty_m");
            add_detail.Columns.Add("order_price");
            add_detail.Columns.Add("order_unit");
            add_detail.Columns.Add("main_dist");
            add_detail.Columns.Add("made_time");
            add_detail.Columns.Add("maker");

            //DataTable dtable = new DataTable();
            //dtable.Columns.Add("consignor");
            //dtable.Columns.Add("asn_no");
            //dtable.Columns.Add("sku");
            //dtable.Columns.Add("pack_code");
            //dtable.Columns.Add("order_qty_m");
            //dtable.Columns.Add("present_qty_m");
            //dtable.Columns.Add("receive_qty_m");
            //dtable.Columns.Add("receive_present_qty_m");
            //dtable.Columns.Add("receive_day");
            //dgv_export.DataSource = dtable;
            //DataTable dt_execl = new DataTable();
            //dt_execl.Columns.Add("customer_order_no");
            //dt_execl.Columns.Add("sku");
            //dgv_execl.DataSource = dt_execl;
            //初始化货主编码 
            try
            {
                dscustomer = main.g_class.comm_get_consignor();
                cb_consignor.ValueMember = "consignor";
                cb_consignor.DisplayMember = "consignor";
                DataRow drnew;
                drnew = dscustomer.Tables[0].NewRow();
                drnew["consignor"] = "";
                drnew["consignor_name"] = "";
                dscustomer.Tables[0].Rows.Add(drnew);
                cb_consignor.DataSource = dscustomer.Tables[0];
                if (dscustomer.Tables[0].Rows.Count > 0) tb_cusname.Text = dscustomer.Tables[0].Rows[0][1].ToString().Trim();

                dtp_made_time.CustomFormat = "yyyy.MM.dd";
                dtp_made_time.Format = DateTimePickerFormat.Custom;
                dtp_made_time_end.CustomFormat = "yyyy.MM.dd";
                dtp_made_time_end.Format = DateTimePickerFormat.Custom;
                //dtp_made_time.Value = System.Convert.ToDateTime(DateTime.Now.ToString("yyyy.MM.dd").Trim());
                //dtp_end.Value = System.Convert.ToDateTime(DateTime.Now.AddDays(7).ToString("yyyy.MM.dd").Trim());

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Consignor's Information", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
            try
            {
                string str_time_sql = "";
                if (main.dbtype == "SQL")
                {
                    str_time_sql = "SELECT CONVERT(char(11),getdate(),102)";
                    str_time = main.dbservice.Sql_exec_selectstring(str_time_sql);
                }
                else
                {
                    str_time_sql = "select to_char(sysdate,'yyyy.MM.dd') from dual";
                    str_time = main.dbservice.oracle_exec_selectstring(str_time_sql);
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.Message);
                str_time = DateTime.Now.ToString("yyyy.MM.dd");
            }
        }

        //导入excel
        private void btn_inexcel_Click(object sender, EventArgs e)
        {
            string str_path;
            str_path = tb_file.Text.Trim();
            if (str_path.Trim() == "") return;

            if (dgv_execl.Rows.Count > 0)
            {
                ((DataTable)dgv_execl.DataSource).Rows.Clear();
            }
            //调用导入数据方法 江森退库入库
            if (comboBox1.Text.Trim() == "标准模板")
            {
                EcxelToDataGridView(str_path, this.dgv_asn);
                f_getsql("", "");
            }
            else if (comboBox1.Text.Trim() == "江森模板" || comboBox1.Text.Trim() == "江森退库入库")
            {
                EcxelToDataGridView_JS(str_path, this.dgv_asn);
                f_getsql_JS("", "");
            }
            else if (comboBox1.Text.Trim() == "无锡江森原料库模板")
            {
                EcxelToDataGridView_WXJS(str_path, this.dgv_asn);
                f_getsql_WXJS_CP("", "");
            }
            else if (comboBox1.Text.Trim() == "无锡江森成品库模板")
            {
                EcxelToDataGridView_WXJS_CP(str_path, this.dgv_asn);
                f_getsql_WXJS_CP("", "");
            }
            else if (comboBox1.Text.Trim() == "进境入库清单")
            {
                EcxelToDataGridView_JS_asn(str_path, this.dgv_asn);
                f_getsql_WXJS_CP("", "");
            }
            else
            {
                MessageBox.Show("请选择模板类型!");
                comboBox1.Focus();
                return;
            }
            if (dgv_asn.Rows.Count == 0) return;
            btn_save.Enabled = true;
            btn_cancel.Enabled = true;
            btn_query.Enabled = false;
            btn_outexcel.Enabled = false;
            btn_inexcel.Enabled = false;
            //MessageBox.Show(main.g_class.comm_getchangestring("Success to Excel ", main.g_info_dataset) + "!");
        }

        //选取文件
        private void btn_file_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text.Trim() == "")
            {
                MessageBox.Show("请选择模板类型!");
                comboBox1.Focus();
                return;
            }
            dgv_asn.DataSource = null;
            dgv_export.DataSource = null;

            //打开一个文件选择框
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Excel文件";
            ofd.FileName = "";
            //ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//为了获取特定的系统文件夹，可以使用System.Environment类的静态方法GetFolderPath()。该方法接受一个Environment.SpecialFolder枚举，其中可以定义要返回路径的哪个系统目录
            ofd.Filter = "Excel文件(*.xls)|*.xls";
            ofd.ValidateNames = true;     //文件有效性验证ValidateNames，验证用户输入是否是一个有效的Windows文件名
            ofd.CheckFileExists = true;  //验证路径有效性
            ofd.CheckPathExists = true; //验证文件有效性
            dgv_export.Visible = false;
            dgv_asn.Visible = true;
            string strName = string.Empty;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                strName = ofd.FileName;
            }

            if (strName == "")
            {
                MessageBox.Show("没有选择Excel文件！无法进行数据导入");
                return;
            }
            tb_file.Text = strName;
            //取文件名
            GetDataFromExcelWithAppointSheetName(strName);
            if (cbx_file.Items.Count > 0)
            {
                cbx_file.SelectedIndex = 0;
            }
        }
        public void EcxelToDataGridView(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;
            str_file = cbx_file.Text.Trim() + "$";
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            strExcel = "select  * from  [" + str_file + "]";
            myCommand = new OleDbDataAdapter(strExcel, strConn);
            ds = new DataSet();
            myCommand.Fill(ds, "table1");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (ds.Tables[0].Rows[i][0].ToString().Trim() == "货主编码" || ds.Tables[0].Rows[i][0].ToString().Trim() == "")
                {
                    ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                    i = i - 1;
                }
            }
            //根据DataGridView的列构造一个新的DataTable
            DataTable tb = new DataTable();
            foreach (DataGridViewColumn dgvc in dgv.Columns)
            {

                if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                {
                    DataColumn dc = new DataColumn();
                    dc.ColumnName = dgvc.DataPropertyName;
                    //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                    tb.Columns.Add(dc);
                }
            }

            //根据Excel的行逐一对上面构造的DataTable的列进行赋值
            foreach (DataRow excelRow in ds.Tables[0].Rows)
            {
                int i = 0;
                DataRow dr = tb.NewRow();
                foreach (DataColumn dc in tb.Columns)
                {

                    dr[dc] = excelRow[i];
                    i++;
                }
                tb.Rows.Add(dr);
            }
            //在DataGridView中显示导入的数据
            dgv.DataSource = tb;
        }
        public void EcxelToDataGridView_JS(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;
            //string str_sql = "";
            //DataSet ds_temp;
            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            DataTable dt_execl = new DataTable();
            dt_execl.Columns.Add("status");
            dt_execl.Columns.Add("Purch.Doc.");
            dt_execl.Columns.Add("Doc. Date");
            dt_execl.Columns.Add("Item");
            dt_execl.Columns.Add("A");
            dt_execl.Columns.Add("Material");
            dt_execl.Columns.Add("Short Text.Doc.");
            dt_execl.Columns.Add("Quantity");
            dt_execl.Columns.Add("To be del.");
            dt_execl.Columns.Add("OUn");
            dt_execl.Columns.Add("Plnt");
            dt_execl.Columns.Add("SLoc");
            dt_execl.Columns.Add("Vendor/supplying plant");
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            dgv_execl.DataSource = dt_execl;
            strExcel = "select  * from  [" + str_file + "]";
            try
            {
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                conn.Close();

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString().Trim() == "货主编码" || ds.Tables[0].Rows[i][0].ToString().Trim() == "" || ds.Tables[0].Rows[i][0].ToString().Trim() == "Purch.Doc.")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }
                }
                d_sum = ds.Tables[0].Rows.Count;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                progressBar1.Visible = true;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F5"].ToString().Trim() + "' and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                            dr["Purch.Doc."] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Item"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["A"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Short Text.Doc."] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Quantity"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["To be del."] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["OUn"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["SLoc"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["Vendor/supplying plant"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    # region 包装编码
                    //根据SKU找出包装

                    str_sql2 = "select * from " + main.g_space + ".mst_pack where inv_org = '" + main.g_org + "' and consignor = '" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' and sku ='" + ds.Tables[0].Rows[i]["sku"].ToString() + "'   and  main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        //显示详细的信息
                        if (ds_temp2.Tables[0].Rows.Count > 0)
                        {
                            //ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                        else
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                            dr["Purch.Doc."] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Item"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["A"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Short Text.Doc."] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Quantity"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["To be del."] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["OUn"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["SLoc"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["Vendor/supplying plant"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pack's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion

                    #region 供应商

                    try
                    {
                        DataSet ds_supply;
                        string str_supply = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                        string[] aa = str_supply.Split(' ');
                        if (aa.Length > 0)
                        {
                            str_supply = aa[0].Trim();

                            if (main.dbtype == "SQL")
                            {
                                str_sql2 = "select ltrim(rtrim(consignor)) consignor,ltrim(rtrim(consignor_name)) consignor_name from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and supply_flag = '1' and consignor = '" + str_supply + "' order by consignor";
                                ds_supply = main.dbservice.Sql_exec_selectsql(str_sql2);
                            }
                            else
                            {
                                str_sql2 = "select trim(consignor) consignor,trim(consignor_name) consignor_name from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and supply_flag = '1'  and consignor = '" + str_supply + "'  order by consignor";
                                ds_supply = main.dbservice.oracle_exec_selectsql(str_sql2);
                            }
                            if (ds_supply.Tables[0].Rows.Count <= 0)
                            {
                                ds.Tables[0].Rows[i]["F12"] = "";
                            }
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["F12"] = "";
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize provider's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion

                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F1"].ToString().Trim() == dgv_execl.Rows[a].Cells["Purch.Doc."].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Purch.Doc."] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Item"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["A"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Short Text.Doc."] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Quantity"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["To be del."] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["OUn"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["SLoc"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["Vendor/supplying plant"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F1"].ToString().Trim() == dgv_execl.Rows[a].Cells["Purch.Doc."].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Purch.Doc."] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Item"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["A"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Short Text.Doc."] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Quantity"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["To be del."] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["OUn"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["SLoc"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["Vendor/supplying plant"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }

                progressBar1.Value = 0;
                progressBar1.Visible = false;
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {
                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }
                ArrayList al = new ArrayList();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    dr["asn_no"] = "";
                    dr["order_day"] = str_time;
                    dr["asn_type"] = "0";
                    dr["customer_order_no"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    dr["lot_attribute5"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    dr["lot_attribute3"] = "非保税";
                    dr["order_unit"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    string str_supply = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    string[] aa = str_supply.Split(' ');
                    if (aa.Length > 0)
                    {
                        dr["supply"] = aa[0];
                    }
                    else
                    {
                        dr["supply"] = "";
                    }
                    dr["in_tax"] = "";
                    dr["out_tax"] = "";
                    dr["arrive_plan_day"] = "";
                    dr["arrive_deadline"] = "";
                    dr["buyer"] = "";
                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    //dr["order_qty_m"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim().Replace(",", "");
                    dr["order_qty_m"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["present_qty_m"] = 0;
                    dr["order_price"] = 0;

                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_order_no asc";
                tb = DV.ToTable();
                //在DataGridView中显示导入的数据
                //dgv.DataSource = DV;
                //main.g_class.DataGridViewToExcel2(dgv);

                #region
                //string str_sql2 = "";
                //DataSet ds_temp2;

                //for (int i = 0; i < tb.Rows.Count; i++)
                //{
                //    progressBar1.Value = i;
                //    #region SKU

                //    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + tb.Rows[i]["consignor"].ToString().Trim() + "' and sku='" + tb.Rows[i]["sku"].ToString().Trim() + "' and main_dist <> 'D'";
                //    try
                //    {
                //        if (main.dbtype == "SQL")
                //            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                //        else
                //            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                //        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明有记录，默认第一条  
                //        {
                //            //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                //            //dr["customer_order_no"] = tb.Rows[i]["customer_order_no"].ToString().Trim();
                //            //dr["sku"] = tb.Rows[i]["sku"].ToString().Trim();
                //            //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                //            tb.Rows.RemoveAt(i);
                //            i = i - 1;
                //            continue;
                //        }
                //    }
                //    catch (System.Exception ee)
                //    {
                //        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                //        return;
                //    }

                //    #endregion

                //    # region 包装编码
                //    //根据SKU找出包装

                //    str_sql2 = "select * from " + main.g_space + ".mst_pack where inv_org = '" + main.g_org + "' and consignor = '" + tb.Rows[i]["consignor"].ToString().Trim() + "' and sku = '" + tb.Rows[i]["sku"].ToString().Trim() + "'  and  main_dist <> 'D'";
                //    try
                //    {
                //        if (main.dbtype == "SQL")
                //            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                //        else
                //            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                //        //显示详细的信息
                //        if (ds_temp2.Tables[0].Rows.Count > 0)
                //        {
                //            tb.Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                //        }
                //        else
                //        {
                //            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                //            dr["customer_order_no"] = tb.Rows[i]["customer_order_no"].ToString().Trim();
                //            dr["sku"] = tb.Rows[i]["sku"].ToString().Trim();
                //            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                //            tb.Rows.RemoveAt(i);
                //            i = i - 1;
                //            continue;
                //        }
                //    }
                //    catch (System.Exception ee)
                //    {
                //        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pack's Information", main.g_info_dataset) + "!" + ee.ToString());
                //        return;
                //    }
                //    #endregion

                //    #region 供应商

                //    try
                //    {
                //        DataSet ds_supply;
                //        if (main.dbtype == "SQL")
                //        {
                //            str_sql2 = "select ltrim(rtrim(consignor)) consignor,ltrim(rtrim(consignor_name)) consignor_name from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and supply_flag = '1' and consignor = '" + tb.Rows[i]["supply"].ToString().Trim() + "' order by consignor";
                //            ds_supply = main.dbservice.Sql_exec_selectsql(str_sql2);
                //        }
                //        else
                //        {
                //            str_sql2 = "select trim(consignor) consignor,trim(consignor_name) consignor_name from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and supply_flag = '1'  and consignor = '" + tb.Rows[i]["supply"].ToString().Trim() + "'  order by consignor";
                //            ds_supply = main.dbservice.oracle_exec_selectsql(str_sql2);
                //        }
                //        if (ds_supply.Tables[0].Rows.Count <= 0)
                //        {                          
                //            tb.Rows[i]["supply"] = "";
                //        }
                //    }
                //    catch (System.Exception ee)
                //    {
                //        MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize provider's Information", main.g_info_dataset) + "!" + ee.ToString());
                //        return;
                //    }
                //    #endregion

                //    //if (dgv_execl.Rows.Count > 0)
                //    //{
                //    //    for (int c = 0; c < dgv_execl.Rows.Count; c++)
                //    //    {
                //    //        if (tb.Rows[i]["customer_order_no"].ToString().Trim() == dgv_execl.Rows[c].Cells["customer_order_no2"].Value.ToString().Trim())
                //    //        {
                //    //            tb.Rows.RemoveAt(i);
                //    //            i = i - 1;
                //    //            break ;
                //    //        }
                //    //    }
                //    //}

                //}
                #endregion
                progressBar1.Visible = false;
                string str_asn_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_asn_no = main.g_class.comm_getaccountno("asn_no");
                    tb.Rows[0]["asn_no"] = str_asn_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_order_no"].ToString().Trim() == tb.Rows[i + 1]["customer_order_no"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["asn_no"] = str_asn_no;
                            }
                            else
                            {
                                str_asn_no = main.g_class.comm_getaccountno("asn_no");
                                tb.Rows[i + 1]["asn_no"] = str_asn_no;
                            }
                        }
                    }
                }
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void EcxelToDataGridView_JS_asn(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;
            //string str_sql = "";
            //DataSet ds_temp;
            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            DataTable dt_execl = new DataTable();
            dt_execl.Columns.Add("status");
            dt_execl.Columns.Add("PO#(订单号)");
            dt_execl.Columns.Add("供应商");
            dt_execl.Columns.Add("SAP#(物料号）");
            dt_execl.Columns.Add("QTY(数量)");
            dt_execl.Columns.Add("UNIT PRICE(单价)");
            dt_execl.Columns.Add("CURRENCY(币种)");
            dt_execl.Columns.Add("NAME(品名)");
            dt_execl.Columns.Add("N.W(净重)");
            dt_execl.Columns.Add("CO(原产国)");
            dt_execl.Columns.Add("UNIT(单位)");
            dt_execl.Columns.Add("HS CODE(海关编码)");
            dt_execl.Columns.Add("进仓单号/发票号码");
            dt_execl.Columns.Add("运单号");
            dt_execl.Columns.Add("到货件数");
            dt_execl.Columns.Add("总毛重");
            dt_execl.Columns.Add("国际贸易条款");
            dt_execl.Columns.Add("运费");
            dt_execl.Columns.Add("保费");
            dt_execl.Columns.Add("杂费");
            dt_execl.Columns.Add("备注");
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            dgv_execl.DataSource = dt_execl;
            strExcel = "select  * from  [" + str_file + "]";
            try
            {
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                conn.Close();

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString().Trim() == "PO#(订单号)" || ds.Tables[0].Rows[i][0].ToString().Trim() == "" || ds.Tables[0].Rows[i][0].ToString().Trim() == "customer_order_no")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }
                }
                d_sum = ds.Tables[0].Rows.Count;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                progressBar1.Visible = true;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    #region SKU

                    str_sql2 = "select  * from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F21"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F3"].ToString().Trim() + "' and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            MessageBox.Show("商品" + ds.Tables[0].Rows[i]["F3"].ToString().Trim() + "不存在!");
                            return;

                            //dt_execl.Columns.Add("PO#(订单号)");
                            //dt_execl.Columns.Add("供应商");
                            //dt_execl.Columns.Add("SAP#(物料号）");
                            //dt_execl.Columns.Add("QTY(数量)");
                            //dt_execl.Columns.Add("UNIT PRICE(单价)");
                            //dt_execl.Columns.Add("CURRENCY(币种)");
                            //dt_execl.Columns.Add("NAME(品名)");
                            //dt_execl.Columns.Add("N.W(净重)");
                            //dt_execl.Columns.Add("CO(原产国)");
                            //dt_execl.Columns.Add("UNIT(单位)");
                            //dt_execl.Columns.Add("HS CODE(海关编码)");
                            //dt_execl.Columns.Add("进仓单号/发票号码");
                            //dt_execl.Columns.Add("运单号");
                            //dt_execl.Columns.Add("到货件数");
                            //dt_execl.Columns.Add("总毛重");
                            //dt_execl.Columns.Add("国际贸易条款");
                            //dt_execl.Columns.Add("运费");
                            //dt_execl.Columns.Add("保费");
                            //dt_execl.Columns.Add("杂费");
                            //dt_execl.Columns.Add("备注");
                            //dt_execl.Columns.Add("货主");

                            //dr["PO#(订单号)"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            //dr["供应商"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            //dr["SAP#(物料号）"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            //dr["QTY(数量)"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            //dr["UNIT PRICE(单价)"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            //dr["CURRENCY(币种)"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            //dr["NAME(品名)"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            //dr["N.W(净重)"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            //dr["CO(原产国)"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            //dr["UNIT(单位)"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            //dr["HS CODE(海关编码)"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            //dr["进仓单号/发票号码"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            //dr["运单号"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            //dr["到货件数"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            //dr["总毛重"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            //dr["国际贸易条款"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                            //dr["运费"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                            //dr["保费"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            //dr["杂费"] = ds.Tables[0].Rows[i]["F19"].ToString().Trim();
                            //dr["备注"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                            //dr["货主"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                            //dr["status"] = "缺档";
                            //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            //ds.Tables[0].Rows.RemoveAt(i);
                            //i = i - 1;
                            //continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    #region 供应商

                    try
                    {
                        DataSet ds_supply;
                        string str_supply = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                        //string[] aa = str_supply.Split(' ');
                        //if (aa.Length > 0)
                        //{
                        //    str_supply = aa[0].Trim();

                        if (main.dbtype == "SQL")
                        {
                            str_sql2 = "select ltrim(rtrim(consignor)) consignor,ltrim(rtrim(consignor_name)) consignor_name from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and supply_flag = '1' and consignor = '" + str_supply + "' order by consignor";
                            ds_supply = main.dbservice.Sql_exec_selectsql(str_sql2);
                        }
                        else
                        {
                            str_sql2 = "select trim(consignor) consignor,trim(consignor_name) consignor_name from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and supply_flag = '1'  and consignor = '" + str_supply + "'  order by consignor";
                            ds_supply = main.dbservice.oracle_exec_selectsql(str_sql2);
                        }
                        if (ds_supply.Tables[0].Rows.Count <= 0)
                        {
                            MessageBox.Show("供应商" + str_supply + "不存在!");
                            return;
                        }
                        //}
                        //else
                        //{
                        //    ds.Tables[0].Rows[i]["F12"] = "";
                        //}
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize provider's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion
                }


                progressBar1.Value = 0;
                progressBar1.Visible = false;
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {
                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }
                ArrayList al = new ArrayList();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                    dr["asn_no"] = "";
                    dr["order_day"] = str_time;
                    dr["asn_type"] = "0";
                    dr["customer_order_no"] = "";
                    //dr["lot_attribute5"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    if (ds.Tables[0].Rows[i]["F22"].ToString().Trim() == "B")
                    {
                        dr["lot_attribute3"] = "保税";
                    }
                    else
                    {
                        dr["lot_attribute3"] = "非保税";
                    }
                    dr["order_unit"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    dr["supply"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                    //string[] aa = str_supply.Split(' ');
                    //if (aa.Length > 0)
                    //{
                    //    dr["supply"] = aa[0];
                    //}
                    //else
                    //{
                    //    dr["supply"] = "";
                    //}
                    dr["in_tax"] = "";
                    dr["out_tax"] = "";
                    dr["arrive_plan_day"] = "";
                    dr["arrive_deadline"] = "";
                    dr["buyer"] = "";
                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    //dr["order_qty_m"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim().Replace(",", "");
                    dr["order_qty_m"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                    dr["present_qty_m"] = 0;
                    dr["order_price"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    //PO#（SAP订单号）
                    dr["lot_attribute6"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    //GRTime（收货时间）
                    dr["lot_attribute7"] = "";
                    //Job#（进仓单号）
                    dr["lot_attribute8"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    //中文品名
                    dr["lot_attribute9"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                    //)HS CODE(海关编码)
                    dr["lot_attribute10"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    //)CO（原产国）
                    dr["lot_attribute11"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    //)UP（UnitPrice单价）
                    dr["lot_attribute12"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    //)NT（UnitNetWeight净重）
                    dr["lot_attribute13"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    //)Currency（币种）
                    dr["lot_attribute14"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();

                    //)运单号
                    dr["carry_no"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                    //)到货件数
                    dr["arrive_ea"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                    //)总毛重
                    dr["gross_sum"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    //)国际贸易条款
                    dr["trade_item"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                    //)运费
                    dr["carry_fee"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                    //)保费
                    dr["keeping_fee"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                    //)杂费
                    dr["other_fee"] = ds.Tables[0].Rows[i]["F19"].ToString().Trim();
                    dr["memo"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                //DV.Sort = "customer_order_no asc";
                tb = DV.ToTable();
                //在DataGridView中显示导入的数据
                //dgv.DataSource = DV;
                //main.g_class.DataGridViewToExcel2(dgv);


                progressBar1.Visible = false;
                //string str_asn_no = "";
                //if (tb.Rows.Count > 0)
                //{
                //    str_asn_no = main.g_class.comm_getaccountno("asn_no");
                //    tb.Rows[0]["asn_no"] = str_asn_no;
                //    if (tb.Rows.Count > 1)
                //    {
                //        for (int i = 0; i < tb.Rows.Count - 1; i++)
                //        {
                //            if (tb.Rows[i]["customer_order_no"].ToString().Trim() == tb.Rows[i + 1]["customer_order_no"].ToString().Trim())
                //            {
                //                tb.Rows[i + 1]["asn_no"] = str_asn_no;
                //            }
                //            else
                //            {
                //                str_asn_no = main.g_class.comm_getaccountno("asn_no");
                //                tb.Rows[i + 1]["asn_no"] = str_asn_no;
                //            }
                //        }
                //    }
                //}
                //if (dgv_execl.Rows.Count > 0)
                //{
                //    main.g_class.DataGridViewToExcel2(dgv_execl);
                //    dgv_execl.DataSource = null;
                //}
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void EcxelToDataGridView_WXJS(string filePath, DataGridView dgv)
        {
            DataSet ds_deliver_place = new DataSet();
            try
            {
                string str_common = "";
                //初始化领料类别
                if (main.dbtype == "SQL")
                {
                    str_common = "select dictionary_code,rtrim(case use_flag when '1' then ltrim(rtrim(content1)) when '2' then ltrim(rtrim(content2)) when '3' then convert(char,number1) else convert(char,number2) end) as dictionary_name from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and ltrim(rtrim(dictionary_name))='deliver_place' order by dictionary_code";
                    ds_deliver_place = main.dbservice.Sql_exec_selectsql(str_common);
                }
                else
                {
                    str_common = "select dictionary_code,case use_flag when '1' then trim(content1) when '2' then trim(content2) when '3' then to_char(number1) else to_char(number2) end as dictionary_name from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and trim(dictionary_name)='deliver_place' order by dictionary_code";
                    ds_deliver_place = main.dbservice.oracle_exec_selectsql(str_common);
                }

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.Message);
            }

            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;
            //string str_sql = "";
            //DataSet ds_temp;
            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            DataTable dt_execl = new DataTable();
            dt_execl.Columns.Add("status");
            dt_execl.Columns.Add("采购订单号");
            dt_execl.Columns.Add("物料");

            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            dgv_execl.DataSource = dt_execl;
            strExcel = "select  * from  [" + str_file + "]";
            try
            {
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString().Trim() == "交货单号" ||
                        ds.Tables[0].Rows[i][0].ToString().Trim() == "默认字段" ||
                        ds.Tables[0].Rows[i][0].ToString().Trim() == "供应商填写" ||
                        ds.Tables[0].Rows[i][0].ToString().Trim() == "供应商代码" ||
                        ds.Tables[0].Rows[i]["F7"].ToString().Trim() == "")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }
                }
                conn.Close();
                d_sum = ds.Tables[0].Rows.Count;
                DataSet ds_temp2;
                string str_sql2 = "";
                string str_sku = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                ds.Tables[0].Columns.Add("order_unit");
                ds.Tables[0].Columns.Add("standby_1");
                ds.Tables[0].Columns.Add("class_code5");
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                progressBar1.Visible = true;

                string[] str_insrt = new string[2];
                DataSet ds_old_no;
                string str_bar;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {

                    progressBar1.Value = i;
                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F2"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F7"].ToString().Trim() + "'  and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            //判断是否为新号
                            #region
                            if (ds.Tables[0].Rows[i]["F7"].ToString().Trim().IndexOf("L") != 0)
                            {
                                string[] aa = ds.Tables[0].Rows[i]["F7"].ToString().Trim().Split('L');
                                str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F2"].ToString().Trim() + "' and sku='" + aa[0] + "'  and main_dist <> 'D'";

                                if (main.dbtype == "SQL")
                                    ds_old_no = main.dbservice.Sql_exec_selectsql(str_sql2);
                                else
                                    ds_old_no = main.dbservice.oracle_exec_selectsql(str_sql2);
                                if (ds_old_no.Tables[0].Rows.Count > 0)//说明有数据
                                {
                                    str_bar = main.g_class.comm_getaccountno("bar_code").Trim();
                                    str_bar = str_bar.Substring(str_bar.Length - 6, 6);
                                    str_sku = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                                    string str_pack = "";
                                    str_pack = ds_old_no.Tables[0].Rows[0]["pack_code"].ToString().Trim() + "L" + aa[1];
                                    str_insrt[0] = "  insert into WMS.mst_sku (inv_org, consignor, sku,          sku_class, " +
                                                                             " barcode, sku_name,  english_name, short_name, " +
                                                                               "pack_code, brand, spec,  type,    " +
                                                                               "  sku_flag,   main_sub_flag,   gross_weight, net_weight,  " +
                                                                               "   tare,        cubage,     price,      sku_len , " +
                                                                               "sku_width, sku_heigth, safe_storage,    max_storage, " +
                                                                               " storage_flag,   shelflife_flag,shelflife_day,      limit_day, " +
                                                                               " pallet_flag, beyond_rate,main_unit,sub_unit," +
                                                                               "convert_modulus,keep_flag,keep_day,bom_flag," +
                                                                               "self_make_flag,external_flag,  warehouseman,fix_flag," +
                                                                               "fix_location,class_code1,class_code2,class_code3," +
                                                                               "class_code4,class_code5,attribute1,attribute2," +
                                                                               "attribute3,  attribute4,attribute5,putaway_rule," +
                                                                               "putaway_rule_tax,allocate_rule,lotno,cycle_check_class," +
                                                                               "mix_sku,mix_lotno,standby_1,standby_2 , " +
                                                                               "standby_3,standby_4,standby_5,standby_6," +
                                                                               "standby_7,standby_8,memo,main_dist," +
                                                                               "made_time, maker)" +
                                                                    " values( '" + main.g_org + "','" + ds_old_no.Tables[0].Rows[0]["consignor"].ToString().Trim() + "','" + ds.Tables[0].Rows[i]["F7"].ToString().Trim() + "','" + ds_old_no.Tables[0].Rows[0]["sku_class"].ToString().Trim() + "'," +
                                                                    "'" + str_bar + "','" + ds_old_no.Tables[0].Rows[0]["sku_name"].ToString().Trim() + "','',''," +
                                                                    " '" + str_pack + "','" + ds_old_no.Tables[0].Rows[0]["brand"].ToString().Trim() + "','" + ds_old_no.Tables[0].Rows[0]["spec"].ToString().Trim() + "','" + ds_old_no.Tables[0].Rows[0]["type"].ToString().Trim() + "'," +
                                                                    "'" + ds_old_no.Tables[0].Rows[0]["sku_flag"].ToString().Trim() + "','" + ds_old_no.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim() + "', 0  , 0 ,0,0,0,0,0,0,0,0,'" +
                                                                    ds_old_no.Tables[0].Rows[0]["storage_flag"].ToString().Trim() + "','" + ds_old_no.Tables[0].Rows[0]["shelflife_flag"].ToString().Trim() + "'," + ds_old_no.Tables[0].Rows[0]["shelflife_day"].ToString().Trim() + "," + ds_old_no.Tables[0].Rows[0]["limit_day"].ToString().Trim() + ",'" + ds_old_no.Tables[0].Rows[0]["pallet_flag"].ToString().Trim() + "',0," +
                                                                    "'" + ds_old_no.Tables[0].Rows[0]["main_unit"].ToString().Trim() + "','" + ds_old_no.Tables[0].Rows[0]["sub_unit"].ToString().Trim() + "'," +
                                                                    ds_old_no.Tables[0].Rows[0]["convert_modulus"].ToString().Trim() + ",'" + ds_old_no.Tables[0].Rows[0]["keep_flag"].ToString().Trim() + "'," + ds_old_no.Tables[0].Rows[0]["keep_day"].ToString().Trim() + ",'" + ds_old_no.Tables[0].Rows[0]["bom_flag"].ToString().Trim() + "','" +
                                                                    ds_old_no.Tables[0].Rows[0]["self_make_flag"].ToString().Trim() + "','','','0','','','','','','','','','','','" + str_sku + "','daiL','" + ds_old_no.Tables[0].Rows[0]["putaway_rule_tax"].ToString().Trim() + "','" + ds_old_no.Tables[0].Rows[0]["allocate_rule"].ToString().Trim() + "','" + ds_old_no.Tables[0].Rows[0]["lotno"].ToString().Trim() + "','','1','1','','1','','','',0,0,0,'','F',getdate(),'" + main.g_user + "')";

                                    str_insrt[1] = "insert into " + main.g_space + ".mst_pack (inv_org, consignor, sku,pack_code,pack_description,pack_unit01,   qty01,    unit01,    length01,    width01,  height01,  weight01,   cubage01,gross01, pack_unit02,   qty02,    unit02,    length02,    width02,  height02,  weight02,   cubage02,gross02, pack_unit03,   qty03,    unit03,    length03,    width03,  height03,  weight03,   cubage03,gross03,pack_unit04,   qty04,    unit04,    length04,    width04,  height04,  weight04,   cubage04,gross04,pack_unit05,   qty05,    unit05,    length05,    width05,  height05,  weight05,   cubage05,gross05,spare_flag,                TI,             HI,      pallet_length,          pallet_width, pallet_height,           memo,      main_dist,   made_time,  maker) values('"
                                        + main.g_org + "','" + ds_old_no.Tables[0].Rows[0]["consignor"].ToString().Trim() + "','" + str_sku + "','" + str_pack + "','" + str_pack + "','EA',       '1',         '',0,0,0,0,0,0,'bag',1,   '',0,0,0,0,0,0,'box',1,   '',0,0,0,0,0,0,'tray',1,   '',0,0,0,0,0,0,'EA',1,   '',0,0,0,0,0,0,'0', 1,1,0,0,0,'','A',getdate(),'" + main.g_user + "')";

                                    main.dbservice.Sql_exec_mutilsql(str_insrt);
                                    ds.Tables[0].Rows[i]["sku"] = str_sku;
                                    ds.Tables[0].Rows[i]["pack_code"] = str_pack;
                                    ds.Tables[0].Rows[i]["order_unit"] = ds_old_no.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                    ds.Tables[0].Rows[i]["standby_1"] = "1";
                                    ds.Tables[0].Rows[i]["class_code5"] = ds_old_no.Tables[0].Rows[0]["class_code5"].ToString().Trim();
                                }
                                else
                                {
                                    DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                    dr["采购订单号"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                                    dr["物料"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                                    dr["status"] = "缺商品档案";
                                    ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                    ds.Tables[0].Rows.RemoveAt(i);
                                    i = i - 1;
                                    continue;
                                }

                            }
                            else
                            {
                                DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                dr["采购订单号"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                                dr["物料"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                                dr["status"] = "缺商品档案";
                                ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                ds.Tables[0].Rows.RemoveAt(i);
                                i = i - 1;
                                continue;
                            }
                            #endregion
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                            ds.Tables[0].Rows[i]["order_unit"] = ds_temp2.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                            ds.Tables[0].Rows[i]["standby_1"] = ds_temp2.Tables[0].Rows[0]["standby_2"].ToString().Trim();
                            ds.Tables[0].Rows[i]["class_code5"] = ds_temp2.Tables[0].Rows[0]["class_code5"].ToString().Trim();

                            if (ds.Tables[0].Rows[i]["pack_code"].ToString().Trim() == "")
                            {
                                DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                dr["采购订单号"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                                dr["物料"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                                dr["status"] = "缺包装档案";
                                ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                ds.Tables[0].Rows.RemoveAt(i);
                                i = i - 1;
                                continue;
                            }
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F6"].ToString().Trim() == dgv_execl.Rows[a].Cells["采购订单号"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["采购订单号"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F6"].ToString().Trim() == dgv_execl.Rows[a].Cells["采购订单号"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["采购订单号"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }

                progressBar1.Value = 0;
                progressBar1.Visible = false;
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {
                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }
                ArrayList al = new ArrayList();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                    dr["asn_no"] = "";
                    dr["order_day"] = str_time;
                    if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "寄售")
                    {
                        dr["asn_type"] = "0";
                        dr["lot_attribute7"] = "寄售-" + ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "正常")
                    {
                        dr["asn_type"] = "0";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "调拨")
                    {
                        dr["asn_type"] = "5";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "委外加工")
                    {
                        dr["asn_type"] = "8";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "外协加工")
                    {
                        dr["asn_type"] = "9";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "销售退货入库")
                    {
                        dr["asn_type"] = "7";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "寄存")
                    {
                        dr["asn_type"] = "6";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "移库")
                    {
                        dr["asn_type"] = "5";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "退库入库")
                    {
                        dr["asn_type"] = "4";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "越库")
                    {
                        dr["asn_type"] = "1";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "货主转移")
                    {
                        dr["asn_type"] = "2";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    else
                    {
                        dr["asn_type"] = "0";
                        dr["lot_attribute7"] = "非寄售";
                    }
                    dr["customer_order_no"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                    dr["supply"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    dr["in_tax"] = "";
                    dr["out_tax"] = "";
                    dr["arrive_plan_day"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                    dr["arrive_deadline"] = "";
                    dr["buyer"] = "";
                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["order_qty_m"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["present_qty_m"] = 0;
                    dr["order_price"] = 0;
                    dr["order_unit"] = ds.Tables[0].Rows[i]["order_unit"].ToString().Trim();

                    dr["carrier"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    dr["carrier_phone"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    dr["vehicle_no"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                    dr["door"] = "";
                    dr["EAS_ORDER"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                    dr["contract_no"] = "";
                    dr["book_time"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();

                    dr["lot_attribute3"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    dr["lot_attribute6"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();

                    dr["lot_attribute1"] = "";
                    dr["lot_attribute2"] = "";
                    dr["memo"] = ds.Tables[0].Rows[i]["F19"].ToString().Trim();
                    dr["ship_no"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                    dr["fly_no"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                    if (ds.Tables[0].Rows[i]["F15"].ToString().Trim() == "Y")
                    {
                        dr["lot_attribute3"] = "保税";
                    }
                    else if (ds.Tables[0].Rows[i]["F15"].ToString().Trim() == "y")
                    {
                        dr["lot_attribute3"] = "保税";
                    }
                    else
                    {
                        dr["lot_attribute3"] = "非保税";
                    }

                    dr["lot_attribute4"] = "";
                    //dr["lot_attribute7"] = "";
                    dr["lot_attribute8"] = "";
                    dr["lot_attribute9"] = "";
                    dr["lot_attribute10"] = "";
                    dr["lot_attribute11"] = "";
                    dr["lot_attribute12"] = "";
                    dr["lot_attribute13"] = "";
                    dr["lot_attribute14"] = "";
                    dr["lot_attribute15"] = "";

                    if (ds.Tables[0].Rows[i]["F10"].ToString().Trim() != "")
                    {
                        if (ds.Tables[0].Rows[i]["F10"].ToString().Trim() == "Y" || ds.Tables[0].Rows[i]["F10"].ToString().Trim() == "y")
                        {
                            dr["standby_1"] = "1";
                        }
                    }
                    else
                    {
                        dr["standby_1"] = ds.Tables[0].Rows[i]["standby_1"].ToString().Trim();
                    }
                    //dr["lot_attribute9"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                    //dr["lot_attribute10"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                    //dr["lot_attribute11"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                    //if (ds.Tables[0].Rows[i]["F22"].ToString().Trim().Length > 10)
                    //{
                    //    dr["lot_attribute12"] = ds.Tables[0].Rows[i]["F22"].ToString().Trim().Substring(0, 10);
                    //}
                    //else
                    //{
                    //    dr["lot_attribute12"] = ds.Tables[0].Rows[i]["F22"].ToString().Trim();
                    //}
                    dr["doc_link"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                    if (ds.Tables[0].Rows[i]["F20"].ToString().Trim() == "")
                    {
                        if (ds_deliver_place.Tables[0].Rows.Count > 0)
                        {
                            DataRow[] dr_de = ds_deliver_place.Tables[0].Select("dictionary_code = '" + ds.Tables[0].Rows[i]["class_code5"].ToString().Trim() + "'");
                            if (dr_de.Length > 0)
                            {
                                dr["carrier_address"] = dr_de[0]["dictionary_name"].ToString().Trim();

                            }
                            else
                            {
                                dr["carrier_address"] = "";
                            }
                        }
                        else
                        {
                            dr["carrier_address"] = "";

                        }
                    }
                    else
                    {
                        dr["carrier_address"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                    }
                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_order_no,asn_type,carrier_address asc";
                tb = DV.ToTable();


                progressBar1.Visible = false;
                string str_asn_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_asn_no = main.g_class.comm_getaccountno("asn_no");
                    tb.Rows[0]["asn_no"] = str_asn_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_order_no"].ToString().Trim() == tb.Rows[i + 1]["customer_order_no"].ToString().Trim()
                                && tb.Rows[i]["asn_type"].ToString().Trim() == tb.Rows[i + 1]["asn_type"].ToString().Trim()
                                && tb.Rows[i]["carrier_address"].ToString().Trim() == tb.Rows[i + 1]["carrier_address"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["asn_no"] = str_asn_no;
                            }
                            else
                            {
                                str_asn_no = main.g_class.comm_getaccountno("asn_no");
                                tb.Rows[i + 1]["asn_no"] = str_asn_no;
                            }
                        }
                    }
                }
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        public void EcxelToDataGridView_WXJS_CP(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;
            //string str_sql = "";
            //DataSet ds_temp;
            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            DataTable dt_execl = new DataTable();
            dt_execl.Columns.Add("status");
            dt_execl.Columns.Add("SAP SO");
            dt_execl.Columns.Add("物料");
            dt_execl.Columns.Add("Alternate Mat No.");
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            dgv_execl.DataSource = dt_execl;
            strExcel = "select  * from  [" + str_file + "]";
            try
            {

                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");


                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString().Trim() == "订单表头" || ds.Tables[0].Rows[i][0].ToString().Trim() == "默认字段" || ds.Tables[0].Rows[i][0].ToString().Trim() == "供应商填写" || ds.Tables[0].Rows[i][0].ToString().Trim() == "供应商代码")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }
                }
                d_sum = ds.Tables[0].Rows.Count;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                progressBar1.Visible = true;
                int i_count = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    i_count = 0;
                    progressBar1.Value = i;
                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F16"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F12"].ToString().Trim() + "'  and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                            dr["SAP SO"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["Alternate Mat No."] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                            if (string.IsNullOrEmpty(ds.Tables[0].Rows[i]["pack_code"].ToString().Trim()))
                            {
                                DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                                dr["SAP SO"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                                dr["物料"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                                dr["Alternate Mat No."] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                                dr["status"] = "缺少包装档案";
                                ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                ds.Tables[0].Rows.RemoveAt(i);
                                i = i - 1;
                                continue;
                            }
                            if (ds_temp2.Tables[0].Rows[0]["sku_class"].ToString().Trim() == "01")
                            {
                                #region

                                str_sql2 = "select count(*) from " + main.g_space + ".inv_sku_batchno a  where a.inv_org='" + main.g_org + "' and a.consignor='" + ds.Tables[0].Rows[i]["F16"].ToString().Trim() + "' and a.lot_attribute6='" + ds.Tables[0].Rows[i]["F19"].ToString().Trim() + "' and a.stock_qty_m>0";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        i_count = main.dbservice.Sql_exec_selectint(str_sql2);
                                    else
                                        i_count = main.dbservice.oracle_exec_selectint(str_sql2);

                                    if (i_count > 0) //说明有记录  
                                    {
                                        DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                                        dr["SAP SO"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                                        dr["物料"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                                        dr["Alternate Mat No."] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                                        dr["status"] = "机组序列号重复";
                                        ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        ds.Tables[0].Rows.RemoveAt(i);
                                        i = i - 1;
                                        continue;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找机组序列号失败!" + ee.ToString());
                                    return;
                                }
                                #endregion

                                #region 判断入库表

                                str_sql2 = "select count(*) from " + main.g_space + ".asn_putaway a  where a.inv_org='" + main.g_org + "' and a.lot_attribute6='" + ds.Tables[0].Rows[i]["F19"].ToString().Trim() + "' and putaway_status='0' ";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        i_count = main.dbservice.Sql_exec_selectint(str_sql2);
                                    else
                                        i_count = main.dbservice.oracle_exec_selectint(str_sql2);

                                    if (i_count > 0) //说明有记录  
                                    {
                                        DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                                        dr["SAP SO"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                                        dr["物料"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                                        dr["Alternate Mat No."] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                                        dr["status"] = "机组序列号重复,存在于入库表中";
                                        ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        ds.Tables[0].Rows.RemoveAt(i);
                                        i = i - 1;
                                        continue;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找机组序列号失败!" + ee.ToString());
                                    return;
                                }
                                #endregion

                            }
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F18"].ToString().Trim() == dgv_execl.Rows[a].Cells["SAP SO"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["SAP SO"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["Alternate Mat No."] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F18"].ToString().Trim() == dgv_execl.Rows[a].Cells["SAP SO"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["SAP SO"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["Alternate Mat No."] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }

                progressBar1.Value = 0;
                progressBar1.Visible = false;
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {
                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }
                ArrayList al = new ArrayList();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                    dr["asn_no"] = "";
                    dr["order_day"] = str_time;
                    dr["asn_type"] = "0";
                    dr["customer_order_no"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                    dr["supply"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    dr["in_tax"] = "";
                    dr["out_tax"] = "";
                    dr["arrive_plan_day"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                    dr["arrive_deadline"] = "";
                    dr["buyer"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["order_qty_m"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    dr["present_qty_m"] = 0;
                    dr["order_price"] = 0;
                    dr["order_unit"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();

                    dr["carrier"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    dr["carrier_phone"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                    dr["vehicle_no"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                    dr["door"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["EAS_ORDER"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    dr["contract_no"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();

                    dr["lot_attribute3"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                    dr["lot_attribute6"] = ds.Tables[0].Rows[i]["F19"].ToString().Trim();
                    dr["lot_attribute9"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                    dr["lot_attribute10"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                    dr["lot_attribute11"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                    if (ds.Tables[0].Rows[i]["F22"].ToString().Trim().Length > 10)
                    {
                        dr["lot_attribute12"] = ds.Tables[0].Rows[i]["F22"].ToString().Trim().Substring(0, 10);
                    }
                    else
                    {
                        dr["lot_attribute12"] = ds.Tables[0].Rows[i]["F22"].ToString().Trim();
                    }
                    dr["doc_link"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();


                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_order_no asc";
                tb = DV.ToTable();


                progressBar1.Visible = false;
                string str_asn_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_asn_no = main.g_class.comm_getaccountno("asn_no");
                    tb.Rows[0]["asn_no"] = str_asn_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_order_no"].ToString().Trim() == tb.Rows[i + 1]["customer_order_no"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["asn_no"] = str_asn_no;
                            }
                            else
                            {
                                str_asn_no = main.g_class.comm_getaccountno("asn_no");
                                tb.Rows[i + 1]["asn_no"] = str_asn_no;
                            }
                        }
                    }
                }
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        ///根据excel的文件的路径提取其中表的数据
        ///</summary>
        ///<paramname="Path">Excel文件的路径</param>
        private void GetDataFromExcelWithAppointSheetName(string Path)
        {
            //连接串
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + Path + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();

            //返回Excel的架构，包括各个sheet表的名称,类型，创建时间和修改时间等　
            DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });
            //包含excel中表名的字符串数组
            string[] strTableNames = new string[dtSheetName.Rows.Count];
            cbx_file.ResetText();
            for (int k = 0; k < dtSheetName.Rows.Count; k++)
            {
                strTableNames[k] = dtSheetName.Rows[k]["TABLE_NAME"].ToString();
                cbx_file.Items.Add(strTableNames[k].Substring(0, strTableNames[k].Length - 1));
            }
            int i = dtSheetName.Rows.Count - 1;
            cbx_file.Text = strTableNames[i].Substring(0, strTableNames[i].Length - 1);
            //OleDbDataAdapter myCommand = null;
            //DataTable dt= new DataTable();
            //从指定的表明查询数据,可先把所有表明列出来供用户选择

            //string strExcel="select*from["+strTableNames[0]+"]";
            //myCommand = new OleDbDataAdapter(strExcel,strConn);
            //dt = new DataTable();
            //myCommand.Fill(dt);
            //dgv_asn.DataSource=dt;//绑定到界面
        }
        //保存
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text.Trim() == "标准模板")
            {
                #region 保存
                decimal d_order_qty_m, d_present_qty_m, d_order_price, d_in_tax, d_out_tax;
                DataSet ds = new DataSet();
                string str_where, str_oldno = "", str_oldconsignor = "";
                Int32 li_count;

                if (dgv_asn.Rows.Count == 0) return;

                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_asn_no = dgv_asn.Rows[i].Cells["asn_no"].Value.ToString().Trim();

                    string str_order_day = dgv_asn.Rows[i].Cells["order_day"].Value.ToString().Trim();

                    string str_asn_type = dgv_asn.Rows[i].Cells["asn_type"].Value.ToString().Trim();

                    string str_customer_order_no = dgv_asn.Rows[i].Cells["customer_order_no"].Value.ToString().Trim();

                    string str_supply = dgv_asn.Rows[i].Cells["supply"].Value.ToString().Trim();
                    if (dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim() == "")
                        d_in_tax = 0;
                    else
                        d_in_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim()), 2);
                    if (dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim() == "")
                        d_out_tax = 0;
                    else
                        d_out_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim()), 2);

                    string str_arrive_plan_day = dgv_asn.Rows[i].Cells["arrive_plan_day"].Value.ToString().Trim();

                    string str_arrive_deadline = dgv_asn.Rows[i].Cells["arrive_deadline"].Value.ToString().Trim();

                    string str_buyer = dgv_asn.Rows[i].Cells["buyer"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim() == "")
                        d_order_qty_m = 0;
                    else
                        d_order_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim() == "")
                        d_present_qty_m = 0;
                    else
                        d_present_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();

                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是 否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_sku  where inv_org = '" + main.g_org + "'and consignor ='" + str_consignor + "' and sku ='" + str_sku + "'";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("sku is not exists ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单号是否为空
                    if (str_asn_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a asn no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //包装编码
                    if (str_pack_code == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a pack code ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //订货主数量是否为空
                    if (d_order_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input order_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_order_day == "")
                    {
                        str_order_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }
                    //订单类型
                    if (str_asn_type == "")
                    {
                        str_asn_type = "0";
                    }
                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".asn_order_header where inv_org = '" + main.g_org + "'and consignor='" + str_consignor + "'and asn_no='" + str_asn_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        int k = 0;
                        ds_update.Tables[0].Clear();
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["asn_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_asn_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["asn_no"] = (string)dgv_asn.Rows[n].Cells["asn_no"].Value.ToString().Trim();
                                dgrow["asn_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                dgrow["present_qty_m"] = (string)dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["order_unit"] = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }

                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                   " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker )  " +
                                                                   "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                          "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_arrive_plan_day + "'" +
                                                               " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', getdate(),'" + main.g_user + "')";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                   " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker )  " +
                                                                   "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                          "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_arrive_plan_day + "'" +
                                                               " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', sysdate,'" + main.g_user + "')";
                        }
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);
                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("Success to save ", main.g_info_dataset) + "!");
                #endregion
            }
            else if (comboBox1.Text.Trim() == "江森模板")
            {
                #region 江森模板保存
                decimal d_order_qty_m, d_present_qty_m, d_order_price, d_in_tax, d_out_tax;
                DataSet ds = new DataSet();
                DataSet ds_temp = new DataSet();
                string str_where, str_oldno = "", str_oldconsignor = "", str_sql = "";
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                Int32 li_count;
                string str_main_unit = "";
                string str_sub_unit = "";
                if (dgv_asn.Rows.Count == 0) return;
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    //如果临时表中有数据，就判断一下如果存在于临时表中的订单号就不能导入
                    bool b_temp2 = false;
                    //if (dgv_execl.Rows.Count > 0)
                    //{
                    //    for (int c = 0; c < dgv_execl.Rows.Count; c++)
                    //    {
                    //        if (dgv_asn.Rows[i].Cells["customer_order_no"].Value.ToString().Trim() == dgv_execl.Rows[c].Cells["customer_order_no2"].Value.ToString().Trim())
                    //        {
                    //            b_temp2 = true;
                    //            break;
                    //        }
                    //    }
                    //}
                    //如果已经存在临时表中，跳过这就条
                    if (b_temp2) continue;

                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_asn_no = dgv_asn.Rows[i].Cells["asn_no"].Value.ToString().Trim();

                    string str_order_day = dgv_asn.Rows[i].Cells["order_day"].Value.ToString().Trim();

                    string str_asn_type = dgv_asn.Rows[i].Cells["asn_type"].Value.ToString().Trim();

                    string str_customer_order_no = dgv_asn.Rows[i].Cells["customer_order_no"].Value.ToString().Trim();

                    string str_supply = dgv_asn.Rows[i].Cells["supply"].Value.ToString().Trim();
                    if (dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim() == "")
                        d_in_tax = 0;
                    else
                        d_in_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim()), 2);
                    if (dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim() == "")
                        d_out_tax = 0;
                    else
                        d_out_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim()), 2);

                    string str_arrive_plan_day = dgv_asn.Rows[i].Cells["arrive_plan_day"].Value.ToString().Trim();

                    string str_arrive_deadline = dgv_asn.Rows[i].Cells["arrive_deadline"].Value.ToString().Trim();

                    string str_buyer = dgv_asn.Rows[i].Cells["buyer"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim() == "")
                        d_order_qty_m = 0;
                    else
                        d_order_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim() == "")
                        d_present_qty_m = 0;
                    else
                        d_present_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();

                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是 否存在
                    //str_where = " select count(*) from " + main.g_space + ".mst_sku  where inv_org = '" + main.g_org + "'and consignor ='" + str_consignor + "' and sku ='" + str_sku + "'";
                    //if (main.dbtype == "SQL")
                    //{
                    //    li_count = main.dbservice.Sql_exec_selectint(str_where);
                    //}
                    //else
                    //{
                    //    li_count = main.dbservice.oracle_exec_selectint(str_where);
                    //}

                    //if (li_count == 0)
                    //{
                    //    MessageBox.Show(main.g_class.comm_getchangestring("sku is not exists ", main.g_info_dataset) + "!");
                    //    dgv_asn.Rows[i].Selected = true;
                    //    break;
                    //}
                    //订单号是否为空
                    if (str_customer_order_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_order_no no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //订货主数量是否为空
                    if (d_order_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input order_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_order_day == "")
                    {
                        str_order_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }
                    //订单类型
                    if (str_asn_type == "")
                    {
                        str_asn_type = "0";
                    }
                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".asn_order_header where inv_org = '" + main.g_org + "'and consignor='" + str_consignor + "'and asn_no='" + str_asn_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        int k = 0;
                        ds_update.Tables[0].Clear();
                        //bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {

                            str_oldno = dgv_asn.Rows[n].Cells["asn_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_asn_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["asn_no"] = str_asn_no;
                                dgrow["asn_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                // dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                dgrow["present_qty_m"] = (string)dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                str_order_unit = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["receive_qty_m"] = 0;
                                dgrow["receive_qty_s"] = 0;
                                dgrow["receive_present_qty_m"] = 0;
                                dgrow["receive_present_qty_s"] = 0;
                                dgrow["receive_status"] = "0";
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["tax_dist"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                //dgrow["receive_status"] = "0";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;
                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        str_main_unit = "";
                                        str_sub_unit = "";
                                        str_main_unit = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        str_sub_unit = ds_temp.Tables[0].Rows[0]["sub_unit"].ToString().Trim();
                                        if (str_main_unit.Trim() == str_order_unit)//单位是主数量
                                        {
                                            dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                            dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else if (str_sub_unit.Trim() == str_order_unit)//辅数量
                                        {
                                            dgrow["order_qty_s"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                            dgrow["order_qty_m"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()) / d_convert, 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else
                                        {
                                            dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                            dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["present_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["shelflife_day"] = Convert.ToInt32(ds_temp.Tables[0].Rows[0]["shelflife_day"].ToString().Trim());
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                        dgrow["cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                    }
                                    else
                                    {
                                        ////MessageBox.Show("未找到商品档案" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim());
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["customer_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }

                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        // if (b_temp) continue;
                        try
                        {
                            #region 加入表头
                            string str_insert;
                            //str_asn_no = main.g_class.comm_getaccountno("asn_no");
                            if (main.dbtype == "SQL")
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status,arrive_day )  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_order_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', getdate(),'" + main.g_user + "',1,'1','" + str_order_day + "')";
                            }
                            else
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status ,arrive_day)  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_order_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', sysdate,'" + main.g_user + "'1,'1','" + str_order_day + "')";
                            }
                            #endregion
                            if (ds_update.Tables[0].Rows.Count > 0)
                            {
                                for (int kk = 0; kk < ds_update.Tables[0].Rows.Count; kk++)
                                {
                                    ds_update.Tables[0].Rows[kk]["asn_no"] = str_asn_no;
                                }
                            }
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                progressBar1.Visible = false;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (comboBox1.Text.Trim() == "江森退库入库")
            {
                #region 江森模板保存
                decimal d_order_qty_m, d_present_qty_m, d_order_price, d_in_tax, d_out_tax;
                DataSet ds = new DataSet();
                DataSet ds_temp = new DataSet();
                string str_where, str_oldno = "", str_oldconsignor = "", str_sql = "";
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                Int32 li_count;
                string str_main_unit = "";
                string str_sub_unit = "";
                if (dgv_asn.Rows.Count == 0) return;
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    //如果临时表中有数据，就判断一下如果存在于临时表中的订单号就不能导入
                    bool b_temp2 = false;
                    //if (dgv_execl.Rows.Count > 0)
                    //{
                    //    for (int c = 0; c < dgv_execl.Rows.Count; c++)
                    //    {
                    //        if (dgv_asn.Rows[i].Cells["customer_order_no"].Value.ToString().Trim() == dgv_execl.Rows[c].Cells["customer_order_no2"].Value.ToString().Trim())
                    //        {
                    //            b_temp2 = true;
                    //            break;
                    //        }
                    //    }
                    //}
                    //如果已经存在临时表中，跳过这就条
                    if (b_temp2) continue;

                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_asn_no = dgv_asn.Rows[i].Cells["asn_no"].Value.ToString().Trim();

                    string str_order_day = dgv_asn.Rows[i].Cells["order_day"].Value.ToString().Trim();

                    string str_asn_type = dgv_asn.Rows[i].Cells["asn_type"].Value.ToString().Trim();

                    string str_customer_order_no = dgv_asn.Rows[i].Cells["customer_order_no"].Value.ToString().Trim();

                    string str_supply = dgv_asn.Rows[i].Cells["supply"].Value.ToString().Trim();
                    if (dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim() == "")
                        d_in_tax = 0;
                    else
                        d_in_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim()), 2);
                    if (dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim() == "")
                        d_out_tax = 0;
                    else
                        d_out_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim()), 2);

                    string str_arrive_plan_day = dgv_asn.Rows[i].Cells["arrive_plan_day"].Value.ToString().Trim();

                    string str_arrive_deadline = dgv_asn.Rows[i].Cells["arrive_deadline"].Value.ToString().Trim();

                    string str_buyer = dgv_asn.Rows[i].Cells["buyer"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim() == "")
                        d_order_qty_m = 0;
                    else
                        d_order_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim() == "")
                        d_present_qty_m = 0;
                    else
                        d_present_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();

                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是 否存在
                    //str_where = " select count(*) from " + main.g_space + ".mst_sku  where inv_org = '" + main.g_org + "'and consignor ='" + str_consignor + "' and sku ='" + str_sku + "'";
                    //if (main.dbtype == "SQL")
                    //{
                    //    li_count = main.dbservice.Sql_exec_selectint(str_where);
                    //}
                    //else
                    //{
                    //    li_count = main.dbservice.oracle_exec_selectint(str_where);
                    //}

                    //if (li_count == 0)
                    //{
                    //    MessageBox.Show(main.g_class.comm_getchangestring("sku is not exists ", main.g_info_dataset) + "!");
                    //    dgv_asn.Rows[i].Selected = true;
                    //    break;
                    //}
                    //订单号是否为空
                    if (str_customer_order_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_order_no no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //订货主数量是否为空
                    if (d_order_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input order_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_order_day == "")
                    {
                        str_order_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }
                    //订单类型
                    //if (str_asn_type == "")
                    //{
                    str_asn_type = "7";
                    //}
                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".asn_order_header where inv_org = '" + main.g_org + "'and consignor='" + str_consignor + "'and asn_no='" + str_asn_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        int k = 0;
                        ds_update.Tables[0].Clear();
                        //bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {

                            str_oldno = dgv_asn.Rows[n].Cells["asn_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_asn_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["asn_no"] = str_asn_no;
                                dgrow["asn_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                // dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                dgrow["present_qty_m"] = (string)dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                str_order_unit = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["receive_qty_m"] = 0;
                                dgrow["receive_qty_s"] = 0;
                                dgrow["receive_present_qty_m"] = 0;
                                dgrow["receive_present_qty_s"] = 0;
                                dgrow["receive_status"] = "0";
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["tax_dist"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                //dgrow["receive_status"] = "0";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;
                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        str_main_unit = "";
                                        str_sub_unit = "";
                                        str_main_unit = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        str_sub_unit = ds_temp.Tables[0].Rows[0]["sub_unit"].ToString().Trim();
                                        if (str_main_unit.Trim() == str_order_unit)//单位是主数量
                                        {
                                            dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                            dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else if (str_sub_unit.Trim() == str_order_unit)//辅数量
                                        {
                                            dgrow["order_qty_s"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                            dgrow["order_qty_m"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()) / d_convert, 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else
                                        {
                                            dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                            dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["present_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["shelflife_day"] = Convert.ToInt32(ds_temp.Tables[0].Rows[0]["shelflife_day"].ToString().Trim());
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                        dgrow["cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                    }
                                    else
                                    {
                                        ////MessageBox.Show("未找到商品档案" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim());
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["customer_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }

                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        // if (b_temp) continue;
                        try
                        {
                            #region 加入表头
                            string str_insert;
                            //str_asn_no = main.g_class.comm_getaccountno("asn_no");
                            if (main.dbtype == "SQL")
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status,arrive_day )  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_order_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', getdate(),'" + main.g_user + "',1,'1','" + str_order_day + "')";
                            }
                            else
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status ,arrive_day)  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_order_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', sysdate,'" + main.g_user + "'1,'1','" + str_order_day + "')";
                            }
                            #endregion
                            if (ds_update.Tables[0].Rows.Count > 0)
                            {
                                for (int kk = 0; kk < ds_update.Tables[0].Rows.Count; kk++)
                                {
                                    ds_update.Tables[0].Rows[kk]["asn_no"] = str_asn_no;
                                }
                            }
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                progressBar1.Visible = false;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (comboBox1.Text.Trim() == "无锡江森原料库模板")
            {
                #region 江森模板保存
                decimal d_order_qty_m, d_present_qty_m, d_order_price, d_in_tax, d_out_tax;
                DataSet ds = new DataSet();
                DataSet ds_temp = new DataSet();
                string str_where, str_oldno = "", str_oldconsignor = "", str_sql = "";
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                Int32 li_count;

                if (dgv_asn.Rows.Count == 0) return;
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    progressBar1.Value = i;


                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_asn_no = dgv_asn.Rows[i].Cells["asn_no"].Value.ToString().Trim();

                    string str_order_day = dgv_asn.Rows[i].Cells["order_day"].Value.ToString().Trim();

                    string str_asn_type = dgv_asn.Rows[i].Cells["asn_type"].Value.ToString().Trim();

                    string str_customer_order_no = dgv_asn.Rows[i].Cells["customer_order_no"].Value.ToString().Trim();
                    string str_memo = dgv_asn.Rows[i].Cells["memo"].Value.ToString().Trim();
                    string str_supply = dgv_asn.Rows[i].Cells["supply"].Value.ToString().Trim();
                    if (dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim() == "")
                        d_in_tax = 0;
                    else
                        d_in_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim()), 2);
                    if (dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim() == "")
                        d_out_tax = 0;
                    else
                        d_out_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim()), 2);

                    DateTime dt_book_time = new DateTime();
                    string str_arrive_plan_day;
                    try
                    {
                        //string str_arrive_plan_day =  dgv_asn.Rows[i].Cells["arrive_plan_day"].Value.ToString().Trim();
                        dt_book_time = Convert.ToDateTime(dgv_asn.Rows[i].Cells["book_time"].Value.ToString().Trim());
                        str_arrive_plan_day = dt_book_time.ToString("yyyy.MM.dd");
                    }
                    catch
                    {
                        str_arrive_plan_day = str_time;
                    }


                    string str_arrive_deadline = dgv_asn.Rows[i].Cells["arrive_deadline"].Value.ToString().Trim();

                    string str_buyer = dgv_asn.Rows[i].Cells["buyer"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim() == "")
                        d_order_qty_m = 0;
                    else
                        d_order_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim() == "")
                        d_present_qty_m = 0;
                    else
                        d_present_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();

                    string str_door = dgv_asn.Rows[i].Cells["door"].Value.ToString().Trim();
                    string str_carrier = dgv_asn.Rows[i].Cells["carrier"].Value.ToString().Trim();
                    string str_carrier_phone = dgv_asn.Rows[i].Cells["carrier_phone"].Value.ToString().Trim();
                    string str_vehicle_no = dgv_asn.Rows[i].Cells["vehicle_no"].Value.ToString().Trim();
                    string str_EAS_ORDER = dgv_asn.Rows[i].Cells["EAS_ORDER"].Value.ToString().Trim();
                    string str_contract_no = dgv_asn.Rows[i].Cells["contract_no"].Value.ToString().Trim();

                    string str_ship_no = dgv_asn.Rows[i].Cells["ship_no"].Value.ToString().Trim();
                    string str_fly_no = dgv_asn.Rows[i].Cells["fly_no"].Value.ToString().Trim();
                    string str_carrier_address = dgv_asn.Rows[i].Cells["carrier_address"].Value.ToString().Trim();
                    #region 判断
                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }


                    //订单号是否为空
                    if (str_customer_order_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_order_no no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //订货主数量是否为空
                    if (d_order_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input order_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_order_day == "")
                    {
                        str_order_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }
                    //订单类型
                    if (str_asn_type == "")
                    {
                        str_asn_type = "0";
                    }
                    #endregion
                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".asn_order_header where inv_org = '" + main.g_org + "'and consignor='" + str_consignor + "'and asn_no='" + str_asn_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {

                        continue;
                    }
                    else
                    {
                        int k = 0;
                        ds_update.Tables[0].Clear();
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["asn_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_asn_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["asn_no"] = str_asn_no;
                                dgrow["asn_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                dgrow["present_qty_m"] = (string)dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["order_unit"] = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["receive_qty_m"] = 0;
                                dgrow["receive_qty_s"] = 0;
                                dgrow["receive_present_qty_m"] = 0;
                                dgrow["receive_present_qty_s"] = 0;
                                dgrow["receive_status"] = "0";

                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();

                                dgrow["tax_dist"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim(); ;
                                ;
                                dgrow["made_time"] = str_order_day;
                                dgrow["maker"] = main.g_user;
                                dgrow["standby_1"] = (string)dgv_asn.Rows[n].Cells["standby_1"].Value.ToString().Trim(); ;
                                dgrow["standby_3"] = (string)dgv_asn.Rows[n].Cells["fly_no"].Value.ToString().Trim(); ;
                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["present_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["shelflife_day"] = Convert.ToInt32(ds_temp.Tables[0].Rows[0]["shelflife_day"].ToString().Trim());
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                        dgrow["cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);

                                    }
                                    else
                                    {
                                        ////MessageBox.Show("未找到商品档案" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim());
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["customer_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }

                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        // if (b_temp) continue;
                        try
                        {
                            #region 加入表头
                            string str_insert;
                            //str_asn_no = main.g_class.comm_getaccountno("asn_no");
                            if (main.dbtype == "SQL")
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status ,carrier,carrier_phone,door,vehicle_no,EAS_ORDER,contract_no,book_time,memo,ship_no,carrier_address,arrive_day)  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_order_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', getdate(),'" + main.g_user + "',1,'1','" + str_carrier.Trim() + "','" + str_carrier_phone.Trim() + "','" + str_door.Trim() + "','" + str_vehicle_no.Trim() + "','" + str_EAS_ORDER + "','" + str_contract_no + "'";
                                if (dt_book_time.ToString() != "")
                                {
                                    str_insert += ",'" + dt_book_time + "','" + str_memo.Trim() + "','" + str_ship_no + "','" + str_carrier_address + "','" + str_order_day + "')";
                                }
                                else
                                {
                                    str_insert += ",getdate(),'" + str_memo.Trim() + "','" + str_ship_no + "','" + str_carrier_address + "')";
                                }
                            }
                            else
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status,carrier,carrier_phone,door,vehicle_no,EAS_ORDER,contract_no ,book_time)  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_arrive_plan_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', sysdate,'" + main.g_user + "'1,'1','" + str_carrier.Trim() + "','" + str_carrier_phone.Trim() + "','" + str_door.Trim() + "','" + str_vehicle_no.Trim() + "','" + str_EAS_ORDER + "','" + str_contract_no + "',sysdate)";
                            }
                            #endregion
                            if (ds_update.Tables[0].Rows.Count > 0)
                            {
                                for (int kk = 0; kk < ds_update.Tables[0].Rows.Count; kk++)
                                {
                                    ds_update.Tables[0].Rows[kk]["asn_no"] = str_asn_no;
                                }
                            }
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                progressBar1.Visible = false;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (comboBox1.Text.Trim() == "无锡江森成品库模板")
            {
                #region 江森模板保存
                decimal d_order_qty_m, d_present_qty_m, d_order_price, d_in_tax, d_out_tax;
                DataSet ds = new DataSet();
                DataSet ds_temp = new DataSet();
                string str_where, str_oldno = "", str_oldconsignor = "", str_sql = "";
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                Int32 li_count;

                if (dgv_asn.Rows.Count == 0) return;
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    progressBar1.Value = i;


                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_asn_no = dgv_asn.Rows[i].Cells["asn_no"].Value.ToString().Trim();

                    string str_order_day = dgv_asn.Rows[i].Cells["order_day"].Value.ToString().Trim();

                    string str_asn_type = dgv_asn.Rows[i].Cells["asn_type"].Value.ToString().Trim();

                    string str_customer_order_no = dgv_asn.Rows[i].Cells["customer_order_no"].Value.ToString().Trim();

                    string str_supply = dgv_asn.Rows[i].Cells["supply"].Value.ToString().Trim();
                    if (dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim() == "")
                        d_in_tax = 0;
                    else
                        d_in_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim()), 2);
                    if (dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim() == "")
                        d_out_tax = 0;
                    else
                        d_out_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim()), 2);

                    string str_arrive_plan_day = dgv_asn.Rows[i].Cells["arrive_plan_day"].Value.ToString().Trim();

                    string str_arrive_deadline = dgv_asn.Rows[i].Cells["arrive_deadline"].Value.ToString().Trim();

                    string str_buyer = dgv_asn.Rows[i].Cells["buyer"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim() == "")
                        d_order_qty_m = 0;
                    else
                        d_order_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim() == "")
                        d_present_qty_m = 0;
                    else
                        d_present_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();

                    string str_door = dgv_asn.Rows[i].Cells["door"].Value.ToString().Trim();
                    string str_carrier = dgv_asn.Rows[i].Cells["carrier"].Value.ToString().Trim();
                    string str_carrier_phone = dgv_asn.Rows[i].Cells["carrier_phone"].Value.ToString().Trim();
                    string str_vehicle_no = dgv_asn.Rows[i].Cells["vehicle_no"].Value.ToString().Trim();
                    string str_EAS_ORDER = dgv_asn.Rows[i].Cells["EAS_ORDER"].Value.ToString().Trim();
                    string str_contract_no = dgv_asn.Rows[i].Cells["contract_no"].Value.ToString().Trim();
                    #region 判断
                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }


                    //订单号是否为空
                    if (str_customer_order_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_order_no no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //订货主数量是否为空
                    if (d_order_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input order_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_order_day == "")
                    {
                        str_order_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }
                    //订单类型
                    if (str_asn_type == "")
                    {
                        str_asn_type = "0";
                    }
                    #endregion
                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".asn_order_header where inv_org = '" + main.g_org + "'and consignor='" + str_consignor + "'and asn_no='" + str_asn_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {

                        continue;
                    }
                    else
                    {
                        int k = 0;
                        ds_update.Tables[0].Clear();
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["asn_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_asn_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["asn_no"] = str_asn_no;
                                dgrow["asn_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                                dgrow["present_qty_m"] = (string)dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["order_unit"] = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["receive_qty_m"] = 0;
                                dgrow["receive_qty_s"] = 0;
                                dgrow["receive_present_qty_m"] = 0;
                                dgrow["receive_present_qty_s"] = 0;
                                dgrow["receive_status"] = "0";
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();

                                dgrow["tax_dist"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim(); ;
                                ;
                                dgrow["made_time"] = str_order_day;
                                dgrow["maker"] = main.g_user;
                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["present_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["shelflife_day"] = Convert.ToInt32(ds_temp.Tables[0].Rows[0]["shelflife_day"].ToString().Trim());
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                        dgrow["cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                    }
                                    else
                                    {
                                        ////MessageBox.Show("未找到商品档案" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim());
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["customer_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }

                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        // if (b_temp) continue;
                        try
                        {
                            #region 加入表头
                            string str_insert;
                            //str_asn_no = main.g_class.comm_getaccountno("asn_no");
                            if (main.dbtype == "SQL")
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status ,carrier,carrier_phone,door,vehicle_no,EAS_ORDER,contract_no,arrive_day)  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_order_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', getdate(),'" + main.g_user + "',1,'1','" + str_carrier.Trim() + "','" + str_carrier_phone.Trim() + "','" + str_door.Trim() + "','" + str_vehicle_no.Trim() + "','" + str_EAS_ORDER + "','" + str_contract_no + "','" + str_order_day + "')";
                            }
                            else
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status,carrier,carrier_phone,door,vehicle_no,EAS_ORDER,contract_no )  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_arrive_plan_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', sysdate,'" + main.g_user + "'1,'1','" + str_carrier.Trim() + "','" + str_carrier_phone.Trim() + "','" + str_door.Trim() + "','" + str_vehicle_no.Trim() + "','" + str_EAS_ORDER + "','" + str_contract_no + "')";
                            }
                            #endregion
                            if (ds_update.Tables[0].Rows.Count > 0)
                            {
                                for (int kk = 0; kk < ds_update.Tables[0].Rows.Count; kk++)
                                {
                                    ds_update.Tables[0].Rows[kk]["asn_no"] = str_asn_no;
                                }
                            }
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                progressBar1.Visible = false;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (comboBox1.Text.Trim() == "进境入库清单")
            {
                #region 进境入库清单
                decimal d_order_qty_m, d_present_qty_m, d_order_price, d_in_tax, d_out_tax, d_gross_sum = 0, d_qty = 0;
                DataSet ds = new DataSet();
                DataSet ds_temp = new DataSet();
                string str_sql = "";
                decimal d_convert = 0, d_cubage = 0, d_net_sum = 0, d_gross = 0;

                string str_insert = "";
                string str_main_unit = "";
                string str_sub_unit = "";
                if (dgv_asn.Rows.Count == 0) return;
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                if (dgv_asn.Rows.Count > 0)
                {
                    if (dgv_asn.Rows[0].Cells["gross_sum"].Value.ToString().Trim() != "")
                    {
                        d_gross_sum = Convert.ToDecimal(dgv_asn.Rows[0].Cells["gross_sum"].Value.ToString().Trim());
                    }

                    for (int i = 0; i < dgv_asn.Rows.Count; i++)
                    {
                        if (dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim() != "")
                        {
                            d_qty += Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim());
                        }

                    }
                    d_gross = Math.Round(d_gross_sum / d_qty, 4);
                    string str_asn_no = main.g_class.comm_getaccountno("asn_no");
                    ds_update.Tables[0].Clear();
                    for (int i = 0; i < dgv_asn.Rows.Count; i++)
                    {

                        progressBar1.Value = i;
                        #region 变量赋值
                        string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                        //str_asn_no = dgv_asn.Rows[i].Cells["asn_no"].Value.ToString().Trim();

                        string str_order_day = dgv_asn.Rows[i].Cells["order_day"].Value.ToString().Trim();

                        string str_asn_type = dgv_asn.Rows[i].Cells["asn_type"].Value.ToString().Trim();

                        string str_customer_order_no = dgv_asn.Rows[i].Cells["customer_order_no"].Value.ToString().Trim();

                        string str_supply = dgv_asn.Rows[i].Cells["supply"].Value.ToString().Trim();
                        if (dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim() == "")
                            d_in_tax = 0;
                        else
                            d_in_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["in_tax"].Value.ToString().Trim()), 2);
                        if (dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim() == "")
                            d_out_tax = 0;
                        else
                            d_out_tax = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["out_tax"].Value.ToString().Trim()), 2);

                        string str_arrive_plan_day = dgv_asn.Rows[i].Cells["arrive_plan_day"].Value.ToString().Trim();

                        string str_arrive_deadline = dgv_asn.Rows[i].Cells["arrive_deadline"].Value.ToString().Trim();

                        string str_buyer = dgv_asn.Rows[i].Cells["buyer"].Value.ToString().Trim();

                        string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                        string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                        if (dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim() == "")
                            d_order_qty_m = 0;
                        else
                            d_order_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                        if (dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim() == "")
                            d_present_qty_m = 0;
                        else
                            d_present_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                        if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                            d_order_price = 0;
                        else
                            d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                        string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                        #endregion
                        #region 判断条件
                        //货主是否为空
                        if (str_consignor == "")
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                            break;
                        }

                        //商品是否为空
                        if (str_sku == "")
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                            dgv_asn.Rows[i].Selected = true;
                            break;
                        }

                        //订货主数量是否为空
                        if (d_order_qty_m == 0)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Please input order_qty_m ", main.g_info_dataset) + "!");
                            dgv_asn.Rows[i].Selected = true;
                            break;
                        }
                        //订单日期
                        if (str_order_day == "")
                        {
                            str_order_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                        }
                        //订单类型
                        if (str_asn_type == "")
                        {
                            str_asn_type = "0";
                        }
                        #endregion
                        d_net_sum += Convert.ToDecimal(dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim());
                        DataRow dgrow = ds_update.Tables[0].NewRow();
                        dgrow["inv_org"] = main.g_org;
                        dgrow["consignor"] = (string)dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();
                        dgrow["asn_no"] = str_asn_no;
                        dgrow["asn_line_no"] = i + 1;
                        dgrow["sku"] = (string)dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();
                        dgrow["pack_code"] = (string)dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();
                        // dgrow["order_qty_m"] = (string)dgv_asn.Rows[n].Cells["order_qty_m"].Value.ToString().Trim();
                        dgrow["present_qty_m"] = (string)dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim();
                        dgrow["order_price"] = (string)dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim();
                        str_order_unit = (string)dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                        dgrow["main_dist"] = "A";
                        dgrow["receive_qty_m"] = 0;
                        dgrow["receive_qty_s"] = 0;
                        dgrow["receive_present_qty_m"] = 0;
                        dgrow["receive_present_qty_s"] = 0;
                        dgrow["receive_status"] = "0";
                        dgrow["lot_attribute3"] = (string)dgv_asn.Rows[i].Cells["lot_attribute3"].Value.ToString().Trim();
                        dgrow["lot_attribute5"] = (string)dgv_asn.Rows[i].Cells["lot_attribute5"].Value.ToString().Trim();
                        dgrow["lot_attribute6"] = (string)dgv_asn.Rows[i].Cells["lot_attribute6"].Value.ToString().Trim();
                        dgrow["lot_attribute7"] = (string)dgv_asn.Rows[i].Cells["lot_attribute7"].Value.ToString().Trim();
                        dgrow["lot_attribute8"] = (string)dgv_asn.Rows[i].Cells["lot_attribute8"].Value.ToString().Trim();
                        dgrow["lot_attribute9"] = (string)dgv_asn.Rows[i].Cells["lot_attribute9"].Value.ToString().Trim();
                        dgrow["lot_attribute10"] = (string)dgv_asn.Rows[i].Cells["lot_attribute10"].Value.ToString().Trim();
                        dgrow["lot_attribute11"] = (string)dgv_asn.Rows[i].Cells["lot_attribute11"].Value.ToString().Trim();
                        dgrow["lot_attribute12"] = (string)dgv_asn.Rows[i].Cells["lot_attribute12"].Value.ToString().Trim();
                        dgrow["lot_attribute13"] = (string)dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim();
                        dgrow["lot_attribute14"] = (string)dgv_asn.Rows[i].Cells["lot_attribute14"].Value.ToString().Trim();
                        dgrow["lot_attribute15"] = (string)dgv_asn.Rows[i].Cells["lot_attribute15"].Value.ToString().Trim();

                        dgrow["tax_dist"] = (string)dgv_asn.Rows[i].Cells["lot_attribute3"].Value.ToString().Trim();
                        //dgrow["receive_status"] = "0";
                        dgrow["made_time"] = (string)dgv_asn.Rows[i].Cells["order_day"].Value.ToString().Trim();
                        dgrow["maker"] = main.g_user;
                        str_sql = "select * from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim() + "' and main_dist <> 'D'";
                        try
                        {
                            if (main.dbtype == "SQL")
                                ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                            else
                                ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                            if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                            {
                                d_convert = 0; 
                                d_cubage = 0;
                                d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                {
                                    d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                }
                                else
                                {
                                    d_cubage = 0;
                                }
                                
                                //if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                //{
                                //    d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                //}
                                //else
                                //{
                                //    d_gross_weight = 0;
                                //}
                                //if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                //{
                                //    d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                //}
                                //else
                                //{
                                //    d_net_weight = 0;
                                //}
                                str_main_unit = "";
                                str_sub_unit = "";
                                str_main_unit = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                str_sub_unit = ds_temp.Tables[0].Rows[0]["sub_unit"].ToString().Trim();
                                if (str_main_unit.Trim() == str_order_unit)//单位是主数量
                                {
                                    dgrow["order_qty_m"] = (string)dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim();
                                    dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                    dgrow["order_unit"] = str_order_unit;
                                }
                                else if (str_sub_unit.Trim() == str_order_unit)//辅数量
                                {
                                    dgrow["order_qty_s"] = (string)dgv_asn.Rows[i].Cells["order_qty_s"].Value.ToString().Trim();
                                    dgrow["order_qty_m"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_s"].Value.ToString().Trim()) / d_convert, 4);
                                    dgrow["order_unit"] = str_order_unit;
                                }
                                else
                                {
                                    dgrow["order_qty_m"] = (string)dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim();
                                    dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                    dgrow["order_unit"] = str_order_unit;
                                }
                                dgrow["convert_modulus"] = d_convert.ToString();
                                dgrow["order_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                dgrow["present_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[i].Cells["present_qty_m"].Value.ToString().Trim()), 4);
                                dgrow["shelflife_day"] = Convert.ToInt32(ds_temp.Tables[0].Rows[0]["shelflife_day"].ToString().Trim());
                                dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                dgrow["cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                //dgrow["gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                //d_gross = Math.Round(d_gross_sum / d_qty, 4);
                                if (i == dgv_asn.Rows.Count - 1)
                                {
                                    dgrow["gross_weight"] = d_gross_sum;
                                }
                                else
                                {
                                    d_gross_sum = d_gross_sum - Math.Round(d_gross * Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                    dgrow["gross_weight"] = Math.Round(d_gross * Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                                    
                                }
                                dgrow["net_weight"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim()) * Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_qty_m"].Value.ToString().Trim()), 4);
                            }

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show("查找商品档案失败!" + ee.ToString());
                            return;
                        }

                        ds_update.Tables[0].Rows.Add(dgrow);

                        if (i == dgv_asn.Rows.Count - 1)
                        {
                            #region 加入表头
                            string str_keep = dgv_asn.Rows[i].Cells["keeping_fee"].Value.ToString().Trim();
                            if (str_keep.Substring(str_keep.Length - 1) == "%")
                            {
                                str_keep = str_keep.Substring(0, str_keep.Length - 1);
                            }
                            //str_asn_no = main.g_class.comm_getaccountno("asn_no");
                            if (main.dbtype == "SQL")
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status,arrive_day,carry_no,keeping_no,net_sum,gross_sum,arrive_ea,carry_fee,keeping_fee,other_fee,trade_item,import_list_no)  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_order_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', getdate(),'" + main.g_user + "',1,'1','" + str_order_day + "','" + dgv_asn.Rows[i].Cells["carry_no"].Value.ToString().Trim() + "','" + dgv_asn.Rows[i].Cells["keeping_no"].Value.ToString().Trim() + "'," + d_net_sum + "," + dgv_asn.Rows[i].Cells["gross_sum"].Value.ToString().Trim() + ",'" + dgv_asn.Rows[i].Cells["arrive_ea"].Value.ToString().Trim() + "'," + dgv_asn.Rows[i].Cells["carry_fee"].Value.ToString().Trim() + "," + str_keep + "," + dgv_asn.Rows[i].Cells["other_fee"].Value.ToString().Trim() + ",'" + dgv_asn.Rows[i].Cells["trade_item"].Value.ToString().Trim() + "','" + dgv_asn.Rows[i].Cells["import_list_no"].Value.ToString().Trim() + "')";
                            }
                            else
                            {
                                str_insert = "insert into " + main.g_space + ".asn_order_header (inv_org,consignor,asn_no,customer_order_no,order_day,asn_type,supply," +
                                                                       " in_tax,out_tax,arrive_plan_day,arrive_deadline,asn_status,arrive_status,buyer,ext_dist,main_dist,made_time,maker,standby_4,book_status ,arrive_day,carry_no,keeping_no,net_sum,gross_sum,arrive_ea,carry_fee,keeping_fee,other_fee,trade_item,import_list_no)  " +
                                                                       "  values('" + main.g_org + "','" + str_consignor + "','" + str_asn_no + "','" + str_customer_order_no + "','" + str_order_day + "'," +
                                                                                                              "'" + str_asn_type + "','" + str_supply + "'," + d_in_tax + "," + d_out_tax + ",'" + str_order_day + "'" +
                                                                   " ,'" + str_arrive_deadline + "','0','0','" + str_buyer + "','0','A', sysdate,'" + main.g_user + "'1,'1','" + str_order_day + "','" + dgv_asn.Rows[i].Cells["carry_no"].Value.ToString().Trim() + "','" + dgv_asn.Rows[i].Cells["keeping_no"].Value.ToString().Trim() + "'," + d_net_sum + "," + dgv_asn.Rows[i].Cells["gross_sum"].Value.ToString().Trim() + ",'" + dgv_asn.Rows[i].Cells["arrive_ea"].Value.ToString().Trim() + "'," + dgv_asn.Rows[i].Cells["carry_fee"].Value.ToString().Trim() + "," + str_keep + "," + dgv_asn.Rows[i].Cells["other_fee"].Value.ToString().Trim() + ",'" + dgv_asn.Rows[i].Cells["trade_item"].Value.ToString().Trim() + "','" + dgv_asn.Rows[i].Cells["import_list_no"].Value.ToString().Trim() + "')";
                            }
                            #endregion
                        }
                    }
                    #region 执行保存
                    try
                    {

                        if (ds_update.Tables[0].Rows.Count > 0)
                        {
                            for (int kk = 0; kk < ds_update.Tables[0].Rows.Count; kk++)
                            {
                                ds_update.Tables[0].Rows[kk]["asn_no"] = str_asn_no;
                            }
                        }
                        if (main.dbtype == "SQL")
                            main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                        else
                            main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);

                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                    #endregion
                }

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                progressBar1.Visible = false;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
        }
        //取消
        private void btn_cancel_Click(object sender, EventArgs e)
        {
            //if (dgv_asn.Rows.Count > 0)
            //{
            dgv_asn.DataSource = null;
            btn_save.Enabled = false;
            btn_cancel.Enabled = false;
            btn_query.Enabled = true;
            btn_outexcel.Enabled = true;
            btn_inexcel.Enabled = true;
            //}
        }
        //导出
        private void btn_outexcel_Click(object sender, EventArgs e)
        {
            //int i_extbatchno ;
            if (dgv_export.Rows.Count > 0)
            {
                //string str_llsql;
                //DataSet ds_llsql =new DataSet();
                ////取导出批次号
                //str_llsql ="select page_no from "+  main.g_space +".mst_account where bill_id ='extbatchno'";
                //if(main.dbtype =="SQL")
                //    ds_llsql =main.dbservice.Sql_exec_selectsql(str_llsql);
                //else
                //    ds_llsql =main.dbservice.oracle_exec_selectsql(str_llsql);
                //i_extbatchno =System.Convert.ToInt32(ds_llsql.Tables[0].Rows[0][0].ToString().Trim()) + 1;
                ////更新导出批次号 
                //string str_sql;
                //DataSet ds_sql =new DataSet();



                main.g_class.DataGridViewToExcel(dgv_export);
                string str_update;
                if (main.dbtype == "SQL")
                    str_update = "update " + main.g_space + ".asn_order_header set ext_dist ='1',updater ='" + main.g_user + "',update_time =getdate()  where inv_org = '" + main.g_org + "' and isnull(ext_dist,'0') ='0' and (asn_status = '1'or arrive_status ='2')  ";
                else
                    str_update = "update " + main.g_space + ".asn_order_header set ext_dist ='1',updater = '" + main.g_user + "',update_time = sysdate  where inv_org = '" + main.g_org + "' and nvl(ext_dist,'0') ='0' and (asn_status = '1'or arrive_status ='2')  ";
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        main.dbservice.Sql_exec_commandsql(str_update);
                    }
                    else
                    {
                        main.dbservice.oracle_exec_commandsql(str_update);
                    }
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to Export", main.g_info_dataset) + "!" + ee.ToString());
                    Cursor.Current = Cursors.Default;
                    return;
                }
                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("Success to Export", main.g_info_dataset) + "!");
            }
        }
        //删除
        private void btn_del_Click(object sender, EventArgs e)
        {
            if (dgv_asn.Rows.Count > 0)
            {
                dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.CurrentRow.Index]);
            }
        }

        private void btn_query_Click(object sender, EventArgs e)
        {

        }

        private void cb_consignor_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cb_consignor.Text.Trim();
            tb_cusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }

        private void cb_consignor_TextChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cb_consignor.Text.Trim();
            tb_cusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }

        private void btn_query_Click_1(object sender, EventArgs e)
        {
            DataSet ds_tmp = new DataSet();
            string str_temp;
            dgv_export.Visible = true;
            dgv_asn.Visible = false;
            dgv_asn.DataSource = null;
            if (main.dbtype == "SQL")

                str_temp = "select a.consignor,a.asn_no,b.sku,b.pack_code,sum(isnull(b.order_qty_m,0)) as order_qty_m,sum(isnull(b.present_qty_m,0)) as present_qty_m," +
                           "sum(isnull(b.receive_qty_m,0)) as receive_qty_m  ,sum(isnull(b.receive_present_qty_m,0))  as receive_present_qty_m,b.receive_day  from " +
                     main.g_space + ".asn_order_header a," + main.g_space + ".asn_order_detail b  where a.inv_org = '" + main.g_org + "' and a.inv_org = b.inv_org and a.consignor = b.consignor and a.asn_no = b.asn_no and " +
                     "isnull(a.ext_dist,'0') = '0' and (a.asn_status = '1'or a.arrive_status ='2') ";
            else
                str_temp = "select a.consignor,a.asn_no,b.sku,b.pack_code,sum(nvl(b.order_qty_m,0)) as order_qty_m,sum(nvl(b.present_qty_m,0)) as present_qty_m," +
                           " sum(nvl(b.receive_qty_m,0)) as receive_qty_m,sum(nvl(b.receive_present_qty_m,0)) as receive_present_qty_m,b.receive_day  from " +
                     main.g_space + ".asn_order_header a," + main.g_space + ".asn_order_detail b  where a.inv_org = '" + main.g_org + "' and a.inv_org = b.inv_org and a.consignor = b.consignor and a.asn_no = b.asn_no and " +
                     "nvl(a.ext_dist,'0') = '0' and (a.asn_status = '1'or a.arrive_status ='2') ";

            //判断是否有货主
            if (cb_consignor.Text.Trim() != "")
            {
                str_temp = str_temp + " and a.consignor = '" + cb_consignor.Text.Trim() + "'  ";
            }
            else //没有货主提取有权限的所有货主
            {
                str_temp = str_temp + " and a.consignor in (select a.consignor from " + main.g_space + ".mst_customer a," + main.g_space + ".sys_user b," + main.g_space + ".sys_user_customer c" +
                           " where b.inv_org = c.inv_org and b.user_id = c.user_id and c.inv_org = a.inv_org and c.consignor = a.consignor and b.inv_org = '" + main.g_org + "' and b.user_id = '" + main.g_user + "' and a.consignor_flag='1')  ";
            }
            if (tb_asn_no.Text.Trim() != "")
            {
                str_temp += " and a.asn_no='" + tb_asn_no.Text.Trim() + "'";
            }
            str_temp += " and b.receive_day between '" + dtp_made_time.Text.ToString().Trim() + "' and '" + dtp_made_time_end.Text.ToString().Trim() + "'  group by a.consignor,a.asn_no,b.sku,b.pack_code,b.receive_day  order by a.asn_no";
            try
            {
                if (main.dbtype == "SQL")
                    ds_tmp = main.dbservice.Sql_exec_selectsql(str_temp);
                else
                    ds_tmp = main.dbservice.oracle_exec_selectsql(str_temp);

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of bill's detail", main.g_info_dataset) + "!" + ee.ToString());

                return;
            }
            if (ds_tmp.Tables[0].Rows.Count > 0)
                dgv_export.DataSource = ds_tmp.Tables[0];
            else
                dgv_export.DataSource = null;

            btn_save.Enabled = false;
            btn_cancel.Enabled = false;
            btn_query.Enabled = true;
            btn_outexcel.Enabled = true;
            btn_inexcel.Enabled = false;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            btn_save.Enabled = true;
            btn_cancel.Enabled = true;
            btn_query.Enabled = false;
            btn_outexcel.Enabled = false;
            btn_inexcel.Enabled = true;
        }

    }
}